import pandas as pd
from pathlib import Path
import sys


mac_path = "/Users/eddy/Desktop/"
win_path = "G:/trading_2025/"
if sys.platform.startswith("win"):
    base_path = Path(win_path)
elif sys.platform == "darwin":
    base_path = Path(mac_path)

data_path = base_path / "shared_data" / "raw_data" / "binance_data" / "spot" / "daily"


exchange = 'binance'
product = 'spot'

for symbol_path in data_path.iterdir():
# for symbol_path in [data_path/'STORJUSDT']:

    # symbol = "STORJUSDT"
    symbol = symbol_path.name
    print(symbol)
    df_list = [pd.read_csv(file) for file in symbol_path.iterdir()]
    df = pd.concat(df_list, ignore_index=True)

    # data clearning
    df = df[["datetime", "open", "high", "low", "close", "volume"]]
    # convert datetime
    df['datetime'] = df['datetime'].str.replace(r'\+.*$', '', regex=True)

    df.duplicated(subset=["datetime"]).sum()

    output_path = Path.cwd().parent / 'data' / exchange/'full_data'
    Path(output_path).mkdir(parents=True, exist_ok=True)
    file_name = f'{symbol}-{product}.csv'
    df.to_csv(output_path/file_name, index=False)
    print(f'file saved to {output_path/file_name}')
